(function ($) {
  "use strict";
  /*
  * author GL
  * params = {
  *   actions 弹出项 Array
  * }
  * */
  var defaults;
  $.actions = function (params) {
    params = $.extend({}, defaults, params);
    var cellsHtml = params.actions.map(function (d, i) {
      return '<div class="gzl-actions__cell ' + (d.className || "") + '">' + d.text + '</div>';
    }).join("");
    var tpl = '<div class="gzl-actions">' +
      '<div class="gzl-actions__mask"></div>' +
      '<div class="gzl-actions__box">' +
      '<div class="gzl-actions__bd">' +
        cellsHtml +
      '</div>' +
      '<div class="gzl-actions__ft">取消</div>' +
      '</div></div>';
    var dialog = $(tpl).appendTo(document.body);
    $.noScroll();
    dialog.find(".gzl-actions__cell").each(function (i, e) {
      $(e).on("click", function() {
        $.closeActions();
        if(params.actions[i] && params.actions[i].onClick) {
          params.actions[i].onClick();
        }
      })
    });
    $(".gzl-section").addClass("no-scroll");
    dialog.find(".gzl-actions__box, .gzl-actions__mask").show().addClass("show");
    dialog.find(".gzl-actions__ft, .gzl-actions__mask").on("click", function () {
      $.closeActions();
    })
  };
  $.closeActions = function () {
    $(".gzl-section").removeClass("no-scroll");
    $(".gzl-actions__box, .gzl-actions__mask").removeClass("show").transitionEnd(function() {
      $(".gzl-actions").remove();
      $.hasScroll();
    });
  };
  defaults = $.actions.prototype.defaults = {
    actions: [{
      text: "菜单",
      className: "color-danger",
      onClick: function() {
        console.log(1);
      }
    },{
      text: "菜单2",
      className: "color-success",
      onClick: function() {
        console.log(2);
      }
    }]
  }
})($);